<?php
namespace Think;


class Csv
{
    //导出csv文件
    public function put_csv($list,$title,$name){
        $file_name="$name".date("Y-m-d",time()).".csv";
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename=" . $file_name);
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        $title=implode(',',$title)."\n";
        $str='';
        foreach ($list as $ke => $va){
            foreach ($va as $k => $v){
                //$str.=iconv('utf-8', 'gb2312', $v).",";
                if(($k=='bank_number') || ($k=='user_phone')){
                    $str.="\t".$v.",";
                }else{
                    $str.=$v.",";
                }
            }
            $str=substr($str,0,-1);
            $str.="\n";
        }
        $data=$title.$str;
        ob_clean();
        echo $data;
    }
}
?>